package com.example.demo.controller;

import com.example.demo.domain.Student;
import com.example.demo.service.StudentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/studentInfoSys")
public class StudentController {
    Logger logger = LoggerFactory.getLogger(FileController.class);
    @Autowired
    StudentService studentService;

    @PostMapping("/student")
    public List<Student> addStudent(@RequestBody Student student){
        logger.info("增加");
        return studentService.addStudent(student);
    }
    @PostMapping("/students")
    public List<Student> addStudents(@RequestBody List<Student> students){
        logger.info("增加");
        return studentService.addStudents(students);
    }
    @GetMapping("/students")
    public List<Student> getAll(){
        logger.info("查找");
        return studentService.getAll();
    }
    @GetMapping("/students/{no}")
    public Student getOneByNo(@PathVariable("no") String no){
        logger.info("查找");
        return studentService.getOneByNo(no);
    }
    @PutMapping("/students/{no}")
    public String updateStudent(@PathVariable("no") String no,@RequestParam("name")String name){
        Student student = new Student(null,name,no,null);
        logger.info("更新");
        return studentService.updateStudent(student);
    }
    @DeleteMapping("/students/{no}")
    public String deleteStudent(@PathVariable("no") String no){
        logger.info("删除");
        return studentService.deleteStudent(no);

    }
}
